package com.yunxi.controller.sat;

import com.yunxi.sat.pojo.HandleVehicleVO;
import com.yunxi.sat.service.HandleVehicleDubboService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.yunxi.core.web.ResponseUtil;
import java.util.*;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.LoginInfo;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 交车信息 前端控制器
 * </p>
 *
 * @author caoYong
 * @since 2019-07-15
 */
@RestController
@RequestMapping("/admin/handleVehicle")
@Api(tags = "sat:handleVehicle", description = "交车信息接口")
public class HandleVehicleController {
    private static final Logger logger = LoggerFactory.getLogger(HandleVehicleController.class);

    @Autowired
    HandleVehicleDubboService handleVehicleDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "查询分页")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "分页数量", required = true, dataType = "int")
    })
    public ApiResult page(HandleVehicleVO handleVehicleVO, Integer pageNum, Integer pageSize,@CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(handleVehicleDubboService.findPageByVO(handleVehicleVO, pageNum, pageSize,loginInfo));
    }

    @GetMapping("/load")
    @ApiOperation(value = "读取单个")
    @ApiImplicitParam(paramType="query", name = "handleId", value = "主键id", required = true, dataType = "String")
    public ApiResult load(String handleId, @CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(handleVehicleDubboService.getInfoById(handleId));
    }

    @GetMapping("/loadByOrderCustomerNo")
    @ApiOperation(value = "读取单个")
    @ApiImplicitParam(paramType="query", name = "orderCustomerNo", value = "非主键id", required = true, dataType = "String")
    public ApiResult loadByOrderCustomerNo(String orderCustomerNo, @CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(handleVehicleDubboService.getInfoByOrderCustomerNo(orderCustomerNo));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存信息")
    public ApiResult save(@RequestBody HandleVehicleVO handleVehicleVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        handleVehicleDubboService.saveOrUpdate(handleVehicleVO,loginInfo);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/del")
    @ApiOperation(value = "删除")
    public ApiResult del(@RequestBody @ApiParam(value = "主键id集合") List<String> list,@CurrentUser LoginInfo loginInfo) throws Exception {
        handleVehicleDubboService.del(list,loginInfo.getUserCode());
        return ResponseUtil.ok("success");
    }

    @PostMapping("/begin")
    @ApiOperation(value = "开始交车")
    public ApiResult begin(@RequestBody HandleVehicleVO handleVehicleVO,@CurrentUser LoginInfo loginInfo) throws Exception {
        handleVehicleVO.setHandleUser(loginInfo.getUserCode());
        handleVehicleVO.setPartnerCode(loginInfo.getPartnerCode());
        handleVehicleDubboService.begin(handleVehicleVO);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/complete")
    @ApiOperation(value = "交车完成")
    public ApiResult complete(@RequestBody HandleVehicleVO handleVehicleVO,@CurrentUser LoginInfo loginInfo) throws Exception {
        handleVehicleDubboService.complete(handleVehicleVO,loginInfo.getUserCode(),loginInfo);
        return ResponseUtil.ok("success");
    }

    @GetMapping("/taskTarget")
    @ApiOperation(value = "销售顾问月目标")
    @ApiImplicitParam(paramType="query", name = "queryDate", value = "查询时间", required = true, dataType = "String")
    public ApiResult taskTarget(String queryDate,@CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(handleVehicleDubboService.taskTarget(queryDate,loginInfo));
    }

    @GetMapping("/allList")
    @ApiOperation(value = "销售顾问本月全部交车")
    public ApiResult allList(HandleVehicleVO handleVehicleVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(handleVehicleDubboService.allList(handleVehicleVO,loginInfo));
    }

    @GetMapping("/handleInfo")
    @ApiOperation(value = "通过客户编号查询交车信息")
    @ApiImplicitParam(paramType="query", name = "customerNo", value = "客户编号", required = true, dataType = "String")
    public ApiResult handleInfo(String customerNo, @CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(handleVehicleDubboService.handleInfo(customerNo));
    }

    @GetMapping("/handleDateList")
    @ApiOperation(value = "交车专员待交车时间列表")
    public ApiResult handleDateList(@CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(handleVehicleDubboService.handleDateList(loginInfo.getUserCode(),loginInfo.getPartnerCode()));
    }

    @PostMapping("/newHandleVehicle")
    @ApiOperation(value = "根据零售单号生成待交车")
    public ApiResult newHandleVehicle(@RequestBody HandleVehicleVO handleVehicleVO,@CurrentUser LoginInfo loginInfo) throws Exception {
        handleVehicleDubboService.newHandleVehicle(handleVehicleVO.getOrderCustomerNo());
        return ResponseUtil.ok("success");
    }

}
